package org.ruoyi.interview.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.ruoyi.common.core.domain.R;
import org.ruoyi.common.core.utils.MapstructUtils;
import org.ruoyi.common.core.utils.StringUtils;
import org.ruoyi.common.log.annotation.Log;
import org.ruoyi.common.log.enums.BusinessType;
import org.ruoyi.common.mybatis.core.page.PageQuery;
import org.ruoyi.common.mybatis.core.page.TableDataInfo;
import org.ruoyi.common.web.core.BaseController;
import org.ruoyi.interview.domain.bo.InterviewQuestionTagBo;
import org.ruoyi.interview.domain.vo.InterviewQuestionTagVo;
import org.ruoyi.interview.service.IInterviewQuestionTagService;

import jakarta.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 题目标签Controller
 *
 * @author ruoyi
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/interview/tag")
public class InterviewQuestionTagController extends BaseController {

    private final IInterviewQuestionTagService interviewQuestionTagService;

    /**
     * 查询题目标签列表
     */
    @SaCheckPermission("interview:tag:list")
    @GetMapping("/list")
    public TableDataInfo<InterviewQuestionTagVo> list(InterviewQuestionTagBo bo, PageQuery pageQuery) {
        return interviewQuestionTagService.selectInterviewQuestionTagList(bo, pageQuery);
    }

    /**
     * 导出题目标签列表
     */
    @SaCheckPermission("interview:tag:export")
    @Log(title = "题目标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(InterviewQuestionTagBo bo, HttpServletResponse response) {
        List<InterviewQuestionTagVo> list = interviewQuestionTagService.selectInterviewQuestionTagList(bo);
        // ExcelUtil.exportExcel(list, "题目标签", InterviewQuestionTagVo.class, response); // 如需导出功能请取消注释
    }

    /**
     * 获取题目标签详细信息
     *
     * @param tagId 题目标签主键
     */
    @SaCheckPermission("interview:tag:query")
    @GetMapping("/{tagId}")
    public R<InterviewQuestionTagVo> getInfo(@PathVariable("tagId") Long tagId) {
        return R.ok(interviewQuestionTagService.selectInterviewQuestionTagById(tagId));
    }

    /**
     * 新增题目标签
     */
    @SaCheckPermission("interview:tag:add")
    @Log(title = "题目标签", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(org.ruoyi.common.core.validate.AddGroup.class) @RequestBody InterviewQuestionTagBo bo) {
        return toAjax(interviewQuestionTagService.insertInterviewQuestionTag(bo) ? 1 : 0);
    }

    /**
     * 修改题目标签
     */
    @SaCheckPermission("interview:tag:edit")
    @Log(title = "题目标签", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(org.ruoyi.common.core.validate.EditGroup.class) @RequestBody InterviewQuestionTagBo bo) {
        return toAjax(interviewQuestionTagService.updateInterviewQuestionTag(bo) ? 1 : 0);
    }

    /**
     * 删除题目标签
     *
     * @param tagIds 题目标签主键串
     */
    @SaCheckPermission("interview:tag:remove")
    @Log(title = "题目标签", businessType = BusinessType.DELETE)
    @DeleteMapping("/{tagIds}")
    public R<Void> remove(@PathVariable Long[] tagIds) {
        return toAjax(interviewQuestionTagService.deleteInterviewQuestionTagByIds(Arrays.asList(tagIds)) ? 1 : 0);
    }
}